package com.wang.jmonkey.ca.handler.code;

import com.wang.jmonkey.common.constant.ValidateConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 获取验证码 holder
 * @Author HeJiawang
 * @Date 2021/5/11 8:55
 */
@Service
public final class ValidateCodeHandlerHolder {

    @Autowired
    private ApplicationContext context;

    Map<String, ValidateCodeHandler> map = new HashMap<>();

    @PostConstruct
    private void init() {
        map = context.getBeansOfType(ValidateCodeHandler.class);
    }

    public ValidateCodeHandler findValidateCodeProcessor(ValidateConstant.ValidateCodeType type) {
        return map.get(type.getKey());
    }
}
